package com.yxq.mdt.app.modules.personal.model;

import com.yxq.mdt.app.base.ibase.IBaseModel;
import com.yxq.mdt.app.modules.personal.bean.EditPicutreResultBean;
import com.yxq.mdt.app.modules.personal.bean.MyPersonalBean;
import com.yxq.mdt.app.net.ApiModel;
import com.yxq.mdt.app.net.BaseObserver;
import com.yxq.mdt.app.net.RetrofitFactory;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.RequestBody;
import retrofit2.http.Field;

/**
 * @author L
 * @time 2019-11-25
 * @describe 我的-个人信息编辑$
 */
public class UserModel implements IBaseModel {

    public void saveGaUserExt(String professionId, String shopAddress, String headimg, String residence,
                              String mobile, String position, String interest, String gsName,
                              String concernProfession, String shopName, String qqNum, String wxImg,
                              String education, String cardShareWord, String topicShareWord, String sex,
                              String oftenToPace, String generation, String posterImg, String shopLogo,
                              String email, String tel, String showHot, String mapLng, String mapLat,
                              String age, String constellation, String birthday, String birthdayShow,
                              String marriage, String marriageShow, String sexual, String sexualShow,
                              String friendsIntention, String loveType, String residenceCode, String hometown,
                              String hometownCode, String userProfile, ApiModel.CommonCallback<String> callback) {

        RetrofitFactory.getJavaRetrofit().create(UserAPI.class)
                .saveGaUserExt(professionId, shopAddress, headimg, residence,
                        mobile, position, interest, gsName,
                        concernProfession, shopName, qqNum, wxImg,
                        education, cardShareWord, topicShareWord, sex,
                        oftenToPace, generation, posterImg, shopLogo,
                        email, tel, showHot, mapLng, mapLat,
                        age, constellation, birthday, birthdayShow,
                        marriage, marriageShow, sexual, sexualShow,
                        friendsIntention, loveType, residenceCode, hometown,
                        hometownCode, userProfile)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<String>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(String respBase) {
                        callback.onSuccess(respBase);
                    }
                });
    }

    /**
     * 获取用户信息
     *
     * @param userId   用户ID
     * @param callback
     */
    public static void getGaUserExtVoById(String userId, ApiModel.CommonCallback<MyPersonalBean> callback) {

        RetrofitFactory.getJavaRetrofit().create(UserAPI.class)
                .getGaUserExtVoById(userId)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<MyPersonalBean>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(MyPersonalBean respBase) {
                        callback.onSuccess(respBase);
                    }
                });
    }

    public static void updateAttribute(RequestBody body, ApiModel.CommonCallback<EditPicutreResultBean> callback) {

        RetrofitFactory.getJavaRetrofit().create(UserAPI.class)
                .updateAttribute(body)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<EditPicutreResultBean>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(EditPicutreResultBean respBase) {
                        callback.onSuccess(respBase);
                    }
                });
    }

    /**
     * 分享统计
     * @param recordType
     * @param handleId
     * @param operType
     * @param callback
     */
    public static void saveGsOperRecord(int recordType, String handleId, int operType, ApiModel.CommonCallback<String> callback) {

        RetrofitFactory.getJavaRetrofit().create(UserAPI.class)
                .saveGsOperRecord(recordType, handleId, operType)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<String>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(String respBase) {
                        callback.onSuccess(respBase);
                    }
                });
    }

    @Override
    public void onDestroy() {

    }
}
